-- storage/scripts/decr_stock.lua
local key = KEYS[1]
local decrAmount = tonumber(ARGV[1])

local stock = tonumber(redis.call('GET', key))
if not stock then
    return -1
end

if stock < decrAmount then
    return 0
end

redis.call('DECRBY', key, decrAmount)
return 1
